package com.itcat.controller;/*
 * @Author: gonhsl
 * @Date:2022-04-02-16:58
 * */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.param.SmsCouponParam;
import com.itcat.mysql.pojo.SmsCoupon;
import com.itcat.service.SmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {
  @Autowired
  private SmsCouponService smsCouponService;
  /**
   * Description:根据优惠券名称和类型分页获取优惠券列表
   * date: 2022/4/2 17:03
   * @author: chp
   * @since JDK 1.8
   */
  @GetMapping("/list")
    public CommonResult findList(@RequestParam Integer pageNum,
                             @RequestParam  Integer pageSize,
                             String name,
                             Integer type){
    Page<SmsCoupon> page = smsCouponService.findList(pageNum, pageSize, name, type);
    CommonPage<SmsCoupon> restPage = CommonPage.restPage(page);
    return  CommonResult.success(restPage);

  }

  /**
   * Description:添加优惠券
   * date: 2022/4/2 17:03
   *
   * @author: chp
   * @since JDK 1.8
   */
  @PostMapping("/create")
  public CommonResult create(@RequestBody SmsCouponParam couponParam) {
    smsCouponService.create(couponParam);
    return CommonResult.success();
  }

  /**
   * Description:删除优惠券
   * date: 2022/4/2 17:03
   *
   * @author: chp
   * @since JDK 1.8
   */
  @PostMapping("/delete/{id}")
  public CommonResult delete(@PathVariable Integer id) {
    smsCouponService.delete(id);
    return CommonResult.success();
  }

  /**
   * Description:修改优惠券
   * date: 2022/4/2 17:03
   *
   * @author: chp
   * @since JDK 1.8
   */
  @PostMapping("/update/{id}")
  public CommonResult update(@PathVariable Integer id,@RequestBody SmsCouponParam couponParam) {

    smsCouponService.update(couponParam,id);
    return CommonResult.success();
  }

  /**
   * Description:修改优惠券
   * date: 2022/4/2 17:03
   *
   * @author: chp
   * @since JDK 1.8
   */
  @GetMapping("/{id}")
  public CommonResult findOne(@PathVariable Integer id) {

    SmsCouponParam one = smsCouponService.findOne(id);
    return CommonResult.success(one);
  }

}
